/*
  ==============================================================================

	VSTRenderLib.cpp
	Created: 28 Nov 2024 11:39:35am
	Author:  leis

  ==============================================================================
*/

#include "VSTRenderLib.h"
#include "PluginChainPool.h"
#include "TaskManager.h"
bool Init(int initInstanceNum, int maxInstanceNum, int pluginNums,
	const char** pluginDescPaths, const char** pluginPresetPaths, int bufferSize)
{
	if (initialed)
	{
		return false;
	}
	for (int i = 0; i < pluginNums; i++)
	{
		PluginInfos::getInstance().AddPluginInfo(pluginDescPaths[i], pluginPresetPaths[i]);
	}
	PluginChainPool::getInstance().Init(initInstanceNum, maxInstanceNum, bufferSize);
	TaskManager::getInstance().Init();
	initialed = true;
	return true;
}
void ProcessAudioFile(const char* inputPath, const char* outputPath, float extendTail, float speed, CallbackFunction cb)
{
	if (initialed) {
		TaskManager::getInstance().AddTask(juce::String(inputPath), juce::String(outputPath), extendTail, speed, cb);
	}
}
bool Exit()
{
	if (initialed)
	{
		TaskManager::getInstance().Exit();
		PluginInfos::getInstance().Exit();
		PluginChainPool::getInstance().Exit();
		initialed = false;
		return true;
	}
	else
	{
		return false;
	}
}
bool InitRealTime(int pluginNums, const char** pluginDescPaths, const char** pluginPresetPaths, int size, int sampleRate)
{
	if (initialed)
	{
		Exit();
		return false;
	}
	for (int i = 0; i < pluginNums; i++)
	{
		PluginInfos::getInstance().AddPluginInfo(pluginDescPaths[i], pluginPresetPaths[i]);
	}
	PluginChainPool::getInstance().Init(1, 1, size, sampleRate, true);
	initialed = true;
	return true;
}
void ProcessAudioBufferRealTime(float* buffer, int bufferSize, int channelNum)
{
	if (initialed)
	{
		PluginChainPool::getInstance().GetRealTimeChain()->ProgressRealTime(buffer, bufferSize, channelNum);
	}
}